"""
@File    ：page_audit.py
@Author  ：ixiaodu
@Date    ：2024/5/14
@Desc    ：
"""
import allure

from page_element import el_audit
from utils.timer import sleep
from common.page_base import Base
from selenium.webdriver.common.by import By


class PageAudit(Base):
    """审核页面"""
    SSGL = By.XPATH, '//div[3]/li/div/span'
    SSGL_ssgl = By.XPATH, '//div[3]/li/ul/div[4]/a/li/span'

    def skip_audit_page(self):
        """跳转审核管理方法"""
        with allure.step("点击宿舍管理按钮"):
            self.base_click(PageAudit.SSGL)
        sleep()
        with allure.step("点击审核管理按钮"):
            self.base_click(PageAudit.SSGL_ssgl)
        sleep(2)

    def click_check_in_audit(self):
        """点击入住审核"""
        self.base_click(el_audit.check_in_audit)
        sleep()

    def click_room_change_audit(self):
        """点击换房审核"""
        self.base_click(el_audit.room_change_audit)
        sleep()

    def click_checkout_audit(self):
        """点击退房审核"""
        self.base_click(el_audit.checkout_audit)
        sleep()

    def click_process_button(self, process_type):
        """点击审核处理按钮"""
        if process_type == "rz":
            self.base_click(el_audit.process_button_checkin)
        elif process_type == "hf":
            self.base_click(el_audit.process_button_change)
        elif process_type == "tf":
            self.base_click(el_audit.process_button_checkout)
        sleep()

    def click_process_button_checkin(self):
        """点击入住审核处理按钮"""
        self.base_click(el_audit.process_button_checkin)
        sleep()

    def click_process_button_change(self):
        """点击换房审核处理按钮"""
        self.base_click(el_audit.process_button_change)
        sleep()

    def click_process_button_checkout(self):
        """点击退房审核处理按钮"""
        self.base_click(el_audit.process_button_checkout)
        sleep()

    def click_pass_button(self):
        """点击审核通过按钮"""
        self.base_click(el_audit.pass_button)
        sleep()

    def click_reject_button(self):
        """点击审核驳回按钮"""
        self.base_click(el_audit.reject_button)
        sleep()

    def click_assign_room_button(self):
        """点击房间分配按钮"""
        self.base_click(el_audit.assign_room_button)
        sleep()

    def input_descr(self, text):
        """输入备注说明"""
        self.base_input(el_audit.descr, text)
        sleep()

    def input_room_number_search(self, room_number):
        """房间搜索输入"""
        self.base_input(el_audit.room_number_search, room_number)
        sleep()

    def click_select_room(self):
        """点击选择房间"""
        self.base_click(el_audit.select_room)
        sleep()

    def click_select_bed(self):
        """点击选择床位"""
        self.base_click(el_audit.select_bed)
        sleep()

    def click_submit_room(self):
        """点击提交房间"""
        self.base_click(el_audit.submit_room)
        sleep()

    def click_submit_audit(self):
        """点击提交审核"""
        self.base_click(el_audit.submit_audit)
        sleep()

    def get_submit_msg(self):
        """获取提示信息"""
        sleep()
        return self.base_get_text(el_audit.submit_msg)

    def audit_pass_allot_room(self, text, room_number):
        """审核通过分配房间"""
        with allure.step("点击入住审核处理按钮"):
            self.click_process_button_checkin()
        with allure.step(f"输入备注说明: {text}"):
            self.input_descr(text)
        with allure.step("点击房间分配按钮"):
            self.click_assign_room_button()
        with allure.step(f"房间号搜索: {room_number}"):
            self.input_room_number_search(room_number)
        with allure.step("点击选择房间按钮"):
            self.click_select_room()
        with allure.step("点击选择床位按钮"):
            self.click_select_bed()
        with allure.step("点击提交房间按钮"):
            self.click_submit_room()
        with allure.step("点击提交审核按钮"):
            self.click_submit_audit()

    def audit_pass(self, process_type, text):
        """审核通过方法，无房间分配"""
        with allure.step(f"点击{process_type}审核处理按钮"):
            self.click_process_button(process_type)
        with allure.step(f"输入备注说明: {text}"):
            self.input_descr(text)
        with allure.step("点击提交审核按钮"):
            self.click_submit_audit()

    def audit_pass_allot_room_fqf(self, text, room_number):
        """审核通过分配房间夫妻房"""
        with allure.step("点击入住审核处理按钮"):
            self.click_process_button_checkin()
        with allure.step(f"输入备注说明: {text}"):
            self.input_descr(text)
        with allure.step("点击房间分配按钮"):
            self.click_assign_room_button()
        with allure.step(f"房间号搜索: {room_number}"):
            self.input_room_number_search(room_number)
        with allure.step("点击选择房间按钮"):
            self.click_select_room()
        with allure.step("点击选择床位按钮"):
            self.click_select_bed()
        with allure.step("点击提交房间按钮"):
            self.click_submit_room()
        with allure.step("点击提交审核按钮"):
            self.click_submit_audit()

    def audit_reject(self, process_type, text):
        """审核驳回方法"""
        with allure.step(f"点击{process_type}审核处理按钮"):
            self.click_process_button(process_type)
        with allure.step(f"输入备注说明: {text}"):
            self.input_descr(text)
        with allure.step("点击审核驳回按钮"):
            self.click_reject_button()
        with allure.step("点击提交审核按钮"):
            self.click_submit_audit()

    def audit_pass_room_change(self, text, room_number):
        """换房审核通过分配房间"""
        with allure.step("点击换房审核按钮"):
            self.click_room_change_audit()
        with allure.step("点击换房审核处理按钮"):
            self.click_process_button_change()
        with allure.step(f"输入备注说明: {text}"):
            self.input_descr(text)
        with allure.step("点击房间分配按钮"):
            self.click_assign_room_button()
        with allure.step(f"房间号搜索: {room_number}"):
            self.input_room_number_search(room_number)
        with allure.step("点击选择房间按钮"):
            self.click_select_room()
        with allure.step("点击选择床位按钮"):
            self.click_select_bed()
        with allure.step("点击提交房间按钮"):
            self.click_submit_room()
        with allure.step("点击提交审核按钮"):
            self.click_submit_audit()
